package cn.fourhundredandeighteen.view.TeacherView.teacherCourseInfo;

import cn.fourhundredandeighteen.UserInfo;
import cn.fourhundredandeighteen.controller.CourseController;
import cn.fourhundredandeighteen.controller.TeacherController;
import cn.fourhundredandeighteen.entity.Course;
import cn.fourhundredandeighteen.entity.Teacher;
import cn.fourhundredandeighteen.utill.Result;
import cn.fourhundredandeighteen.utill.ViewUtill;
import cn.fourhundredandeighteen.view.Component.Container;

import javax.swing.*;
import java.util.*;

public class techercourse {

    public CourseController courseController = new CourseController();
    TeacherController teacherController = new TeacherController();

    public JScrollPane techercourse() {//获取学生已选课程

        Result<List<Course>> listResult = teacherController.selectTeacherCreateCourse(UserInfo.Session);
        List<Course> data = listResult.getData();
        JScrollPane jScrollPane = ViewUtill.viewCourseTable(data);
        return jScrollPane;
    }

    public Map<Integer, String[]> courseInfo() {
        // TODO add your code here
        Map<Integer, String[]> integerStringHashMap = new HashMap<>();

        //获取字段
        String[] Lablename = {"课程id:", "课程名称:", "课时:", "学分:", "教师id:", "授课人数:"};
        //获取数据
        integerStringHashMap.put(1, Lablename);//数据键值对
        return integerStringHashMap;
    }

    public String setcourseInfo(ArrayList<JTextField> Data) {
        // TODO add your code here
//            if (!NumberUtil.Password(String.valueOf(Data.get(3).getText()))){
//                return "请输入6位数字密码";
//            }
//            if (NumberUtil.Age(String.valueOf(Data.get(2).getText()))){
//                return "请输入正确年龄";
//            }
        //获取需要上传的数据并保存至数组

        try {
            Course course = new Course();
            Date date = new Date();
            course.setCourseName(String.valueOf(Data.get(1).getText()));
            course.setCourseHour(Integer.valueOf(Data.get(2).getText()));
            course.setCourseScore(Integer.valueOf(String.valueOf(Data.get(3).getText())));
            course.setTeacherId(Long.valueOf(Data.get(4).getText()));
            Result<Teacher> teacherResult = teacherController.teacherInfo(Long.valueOf(Data.get(4).getText()));
            if (teacherResult.getData() == null) {
                return "请检查教师id是否正确";
            }
            course.setCourseCount(Integer.valueOf(Data.get(5).getText()));
            course.setCreateTime(date);
            course.setUpdateTime(date);
            Result result = courseController.addCourse(course);
            if (result.getMassage() == "SUCCESS") {
                return "添加成功";
            } else {
                return "添加失败";
            }
        } catch (NumberFormatException numberFormatException) {
            return "请输入正确的参数";
        }

    }

    public String updatacourseInfo(ArrayList<JTextField> Data) {
        // TODO add your code here
//            if (!NumberUtil.Password(String.valueOf(Data.get(3).getText()))){
//                return "请输入6位数字密码";
//            }
//            if (NumberUtil.Age(String.valueOf(Data.get(2).getText()))){
//                return "请输入正确年龄";
//            }


        //获取需要上传的数据并保存至数组


        try {
            Course course = new Course();
            Date date = new Date();
            course.setCourseId(Long.valueOf(Data.get(0).getText()));
            course.setCourseName(String.valueOf(Data.get(1).getText()));
            course.setCourseHour(Integer.valueOf(Data.get(2).getText()));
            course.setCourseScore(Integer.valueOf(String.valueOf(Data.get(3).getText())));
            course.setTeacherId(UserInfo.Session);
            course.setCourseCount(Integer.valueOf(Data.get(5).getText()));
            course.setCreateTime(date);
            course.setUpdateTime(date);
            Result result = courseController.upCourse(course);   //k课程信息更新接口

            if (result.getMassage() == "SUCCESS") {
                Container.getInstance().upDatePage();
                return "修改成功";

            } else {
                return "修改失败";
            }
        } catch (NumberFormatException numberFormatException) {
            return "请输入正确的参数";
        }

    }


}
